<?php
declare (strict_types = 1);

namespace app\api\controller\mall;
use app\BaseController;
use app\common\business\Goods;
use app\common\lib\Show;
use think\facade\Request;

class Lists extends BaseController
{
    public function index()
    {
        $pageSize = Request::param('page_size', 10, 'intval');
        $categoryId = Request::param('category_id', 0, 'intval');
        if (!$categoryId) return Show::success();

        $data = ['category_path_id' => $categoryId];

        $field = Request::param('field', 'listorder', 'trim');
        $order = Request::param('order', 2, 'intval');
        $order = $order == 2 ? 'desc' : 'asc';
        $order = [$field => $order];

        $goods = new Goods();
        $result = $goods->getNormalLists($data, $pageSize, $order);
        return Show::success($result);
    }
}
